#include "udpserver.hpp"
#include <memory>
#include "inetaddr.hpp"
#include "rounte.hpp"
#include "threadpool.hpp"
using namespace udpserver;
using namespace myaddr;
using namespace myrounte;
using namespace ThreadPool;
std::string func(const std::string &str)
{
    std::string ret = "hello ";
    ret += str;
    return ret;
}
using task_t = std::function<void()>;
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "usage : ./udpserver port" << std::endl;
        exit(1);
    }
    uint16_t port = std::stoi(argv[1]);
    // 1. Rounte  消息路由
    Rounte r;
    // 2. 线程池
    Threadpool<task_t> *tpl = Threadpool<task_t>::GetInstance();
    tpl->Start();
    // 3. 网络通信
    std::unique_ptr<UdpServer>
        server = std::make_unique<UdpServer>(port, [&r, &tpl](int sockfd, const std::string &massage, const InetAddr &peer)
                                             {
            //调用
            // r.Massage_Rounte(sockfd,massage, peer);
            // return "send massage";
            auto t = bind(&Rounte::Massage_Rounte,&r,sockfd,massage,peer);
            tpl->Enqueue(t); });

    server->Init();
    server->Start();
    return 0;
}